package com.boho.ecp.util;

import java.util.List;

public class ArrayUtils {

	public static String toString(Integer[] array){
		String arr = org.apache.commons.lang.ArrayUtils.toString(array);
		return arr.replace("{", "").replace("}", "");
	}
	
	public static String toString(List list){
		String arr = org.apache.commons.lang.ArrayUtils.toString(list);
		return arr.replace("[", "").replace("]", "");
	}
	
	public static String toArray(List list){
		String str = "";
		StringBuilder sb = new StringBuilder();
		for (Object obj : list) {
			sb.append("'").append(obj.toString()).append("',");
		}
		if(sb.length() > 0){
			str = sb.substring(0, sb.length() - 1);
		}
		return str;
	}
	
	public static Long[] ObjArrayToLongArray(Object[] obj) throws Exception{
		Long[] longs = null;
		if(obj != null && obj.length > 0){
			int size = obj.length;
			longs = new Long[size];
			for(int i = 0; i < size; i++){
				longs[i] = Long.parseLong(obj[i].toString());
			}
		}
		return longs;
	}
	
	public static Integer[] ObjArrayToIntArray(Object[] obj) throws Exception{
		Integer[] ints = null;
		if(obj != null && obj.length > 0){
			int size = obj.length;
			ints = new Integer[size];
			for(int i = 0; i < size; i++){
				ints[i] = Integer.parseInt(obj[i].toString());
			}
		}
		return ints;
	}
	
	public static String[] ObjArrayToStringArray(Object[] obj) throws Exception{
		String[] str = null;
		if(obj != null && obj.length > 0){
			int size = obj.length;
			str = new String[size];
			for(int i = 0; i < size; i++){
				str[i] = String.valueOf(obj[i].toString());
			}
		}
		return str;
	}
}
